package ${package.Controller};


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.biao.transaction.example.common.enums.ResponseCode;
import com.biao.transaction.example.dto.ApiResponseDTO;
import com.biao.transaction.example.dto.SearchDTO;
import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
<#if restControllerStyle == false>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>


/**
 * <p>
    * ${table.comment!} 前端控制器
    * </p>
 *
 * @author ${author}
 * @since ${date}
 * @version v1.0
 */
<#if restControllerStyle>
@Api(tags = {"${table.comment!}接口"})
@Slf4j
@RestController
<#else>
@Controller
</#if>
@RequestMapping("/api<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${entity?uncap_first}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
 <#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
 <#else>
public class ${table.controllerName} {
 </#if>

    @Autowired
    private ${table.serviceName} ${table.serviceName?uncap_first};

    /**
    * @description:分页获取${table.comment!}列表
    * @author:${author}
    * @createTime:${date}
    * @version：1.0
    **/
    @ApiOperation(value = "分页获取${table.comment!}列表")
    @RequestMapping("/list")
    public ApiResponseDTO list(@RequestBody SearchDTO searchDTO) {
    IPage<${entity}> ${entity?uncap_first}IPage = ${table.serviceName?uncap_first}.getPage(searchDTO);
    return new ApiResponseDTO(${entity?uncap_first}IPage);
    }

    /**
     * @description：新添或更新${table.comment!}
     * @author:${author}
     * @createTime:${date}
     * @version：1.0
     **/
    @ApiOperation(value = "新添或更新${table.comment!}")
    @RequestMapping("/saveOrUpdate")
    public ApiResponseDTO saveOrUpdate(@RequestBody ${entity} ${entity?uncap_first}) {
        boolean updateResult = ${table.serviceName?uncap_first}.updateById(${entity?uncap_first});
        if(updateResult == true){
            return new ApiResponseDTO();
        }
        else{
            return new ApiResponseDTO(ResponseCode.UPDATE_FAIL.getCode(), ResponseCode.UPDATE_FAIL.getMsg());
        }
    }

    /**
     * @description：删除${table.comment!}
     * @author:chenwenbiao
     * @createTime:${date}
     * @version：1.0
     **/
    @ApiOperation(value = "删除${table.comment!}")
    @RequestMapping("/delete")
    public ApiResponseDTO delete(@RequestParam("id")Integer id) {
        boolean deleteResult = ${table.serviceName?uncap_first}.delete(id);
        if(deleteResult == true){
            return new ApiResponseDTO();
        }
        else{
            return new ApiResponseDTO(ResponseCode.DELETE_FAIL.getCode(), ResponseCode.DELETE_FAIL.getMsg());
        }
    }


}
</#if>